package com.sfh.cp.util.lub;

import android.support.annotation.NonNull;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;


public class Luban {
    int mLeastCompressSize = 200;
    InputStreamProvider provider;

    public Luban leastCompressSize(int leastCompressSize) {
        this.mLeastCompressSize = leastCompressSize;
        return this;
    }

    public Luban load(final String inputFile) {
        provider = new InputStreamProvider() {
            @Override
            public InputStream open() throws IOException {
                return new FileInputStream(inputFile);
            }

            @Override
            public String getPath() {
                return inputFile;
            }
        };
        return this;
    }

    public File compress(@NonNull File dstFile) throws IOException {
        if (Checker.SINGLE.isNeedCompress(mLeastCompressSize, provider.getPath())) {
            return new Engine(provider, dstFile).compress();
        } else {
            return new File(provider.getPath());
        }
    }
}
